<!-- 商品详情 > 评价 -->
<template>
	<view class="evaluation">
		<view class="top">
			<view class="title">
				<text>评价（{{ total }}）</text>
				<text>好评度{{ rate }}%</text>
			</view>
			<view class="_label">
				<text @click="changeType(1)">全部好评</text>
				<text @click="changeType(2)">中评</text>
				<text @click="changeType(3)">差评</text>
			</view>
		</view>

		<view class="content">
			<Default
				:showflag="showflag"
				:type='4'
			></Default>
			<view class="contentitem" v-if="commentData.length > 0" v-for="(item, index) in commentData">
				<view class="name">
					<view class="left"><image :src="item.user.avatar" mode=""></image></view>
					<view class="right">
						<view class="username">{{ item.user.nickname }}</view>
						<view><uni-rate :readonly="true" v-model="value" :size="12" :margin="4" /></view>
					</view>
				</view>
				<view class="goodscontent">{{ item.content }}</view>
				<view class="goodimg" v-if="item.image" >
					<image v-for="(v, n) in item.image" :src="v" mode=""></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			showflag: false,
			value: 5,
			commentData: [],  // 评论内容
			id: '', // 商品id
			total: 0, // 评论总数
			is_type: 1,
			rate: 100, // 好评率
			
			
		};
	},
	onLoad(option) {
		if (option.id) {
			this.id = option.id
		}
		this.getComment()
	},
	methods: {
		//  获取评论
		getComment() {
			var that = this
			that.$mrequest({
				url: 'Mini/goods/goods_comments',
				method: 'GET',
				data: {
					id: that.id,
					is_type: that.is_type
				},
				callBack: function callBack (res) {
					if (res.status) {
						that.commentData = res.data.data
						that.total = res.data.total
						that.rate = res.data.rate
						if (that.commentData.length > 0) {
							that.showflag = false
						} else {
							that.showflag = true
						}
					}
				},
				fail: function fail (res) {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			})
		},
		//  改变is_type
		changeType(num) {
			if (num == this.is_type) return
			this.is_type = num
			this.getComment()
		},
	}
};
</script>

<style lang="scss">
.evaluation {
	.top {
		width: 100%;
		box-sizing: border-box;
		padding: 0 30rpx;
		// min-height: 270rpx;
		background: #fff;
		border-top: 6rpx solid #f7f8f9;
		border-bottom: 6rpx solid #f7f8f9;
		.title {
			height: 80rpx;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			text:nth-child(1) {
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}
			text:nth-child(2) {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999999;
			}
		}
		._label {
			text {
				display: inline-block;
				min-width: 120rpx;
				height: 46rpx;
				line-height: 46rpx;
				font-size: 22rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #ffffff;
				margin: 20rpx 40rpx;
				margin-left: 0;
				background: #34c39e;
				border-radius: 23rpx;
				text-align: center;
				padding: 0 10rpx;
			}
		}
	}

	.content {
		width: 100%;
		margin-bottom: 40rpx;
		.contentitem {
			width: 100%;
			// min-height: 460rpx;
			box-sizing: border-box;
			padding: 14rpx 30rpx;
			border-bottom: 2rpx solid #d2d2d2;
			.name {
				width: 100%;
				height: 90rpx;
				display: flex;
				align-items: top;
				justify-content: flex-start;
				.left {
					width: 12%;
					overflow: hidden;
					image {
						margin-top: 14rpx;
						width: 70rpx;
						height: 70rpx;
						border-radius: 50%;
					}
				}
				.right {
					width: 88%;
					.username {
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #333333;
						line-height: 40rpx;
						margin: 10rpx 0;
					}
				}
			}
			.goodscontent {
				width: 100%;
				font-size: 28rpx;
				margin: 10rpx 0;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box; //作为弹性伸缩盒子模型显示。
				-webkit-box-orient: vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
				-webkit-line-clamp: 2; //显示的行
			}
			.goodimg {
				image {
					display: inline-block;
					width: 205rpx;
					height: 205rpx;
					margin: 10rpx 24rpx;
					margin-left: 0;
				}
			}
		}
	}
}
</style>
